﻿using System;
using System.Collections.Generic;
using System.Linq;
using Helpers;
using TaleWorlds.CampaignSystem.Actions;
using TaleWorlds.CampaignSystem.CharacterDevelopment;
using TaleWorlds.CampaignSystem.Conversation;
using TaleWorlds.CampaignSystem.Extensions;
using TaleWorlds.CampaignSystem.MapEvents;
using TaleWorlds.CampaignSystem.Settlements;
using TaleWorlds.Core;
using TaleWorlds.Localization;
using TaleWorlds.SaveSystem;

namespace TaleWorlds.CampaignSystem.Issues
{
	// Token: 0x02000319 RID: 793
	public class RaidAnEnemyTerritoryIssueBehavior : CampaignBehaviorBase
	{
		// Token: 0x06002DA6 RID: 11686 RVA: 0x000BF1CE File Offset: 0x000BD3CE
		public override void RegisterEvents()
		{
			CampaignEvents.OnCheckForIssueEvent.AddNonSerializedListener(this, new Action<Hero>(this.OnCheckForIssue));
		}

		// Token: 0x06002DA7 RID: 11687 RVA: 0x000BF1E8 File Offset: 0x000BD3E8
		public void OnCheckForIssue(Hero hero)
		{
			if (this.ConditionsHold(hero))
			{
				Campaign.Current.IssueManager.AddPotentialIssueData(hero, new PotentialIssueData(new PotentialIssueData.StartIssueDelegate(this.OnStartIssue), typeof(RaidAnEnemyTerritoryIssueBehavior.RaidAnEnemyTerritoryIssue), IssueBase.IssueFrequency.VeryCommon, null));
				return;
			}
			Campaign.Current.IssueManager.AddPotentialIssueData(hero, new PotentialIssueData(typeof(RaidAnEnemyTerritoryIssueBehavior.RaidAnEnemyTerritoryIssue), IssueBase.IssueFrequency.VeryCommon));
		}

		// Token: 0x06002DA8 RID: 11688 RVA: 0x000BF24C File Offset: 0x000BD44C
		private bool ConditionsHold(Hero issueGiver)
		{
			return issueGiver.IsLord && issueGiver.MapFaction.IsKingdomFaction && issueGiver == ((Kingdom)issueGiver.MapFaction).Leader && issueGiver.GetTraitLevel(DefaultTraits.Mercy) <= 0 && issueGiver.GetTraitLevel(DefaultTraits.Calculating) >= 0 && this.GetAtWarWithFactionCount(issueGiver) >= 1;
		}

		// Token: 0x06002DA9 RID: 11689 RVA: 0x000BF2AC File Offset: 0x000BD4AC
		private int GetAtWarWithFactionCount(Hero issueGiver)
		{
			int num = 0;
			foreach (Kingdom kingdom in Kingdom.All)
			{
				if (issueGiver.MapFaction != kingdom && issueGiver.MapFaction.IsAtWarWith(kingdom) && kingdom.Settlements.Count > 1)
				{
					num++;
				}
			}
			return num;
		}

		// Token: 0x06002DAA RID: 11690 RVA: 0x000BF324 File Offset: 0x000BD524
		private IssueBase OnStartIssue(in PotentialIssueData pid, Hero issueOwner)
		{
			return new RaidAnEnemyTerritoryIssueBehavior.RaidAnEnemyTerritoryIssue(issueOwner);
		}

		// Token: 0x06002DAB RID: 11691 RVA: 0x000BF32C File Offset: 0x000BD52C
		public override void SyncData(IDataStore dataStore)
		{
		}

		// Token: 0x04000DA8 RID: 3496
		private const int BaseRewardGold = 15000;

		// Token: 0x04000DA9 RID: 3497
		private const int ExtraRewardMultiplier = 3000;

		// Token: 0x04000DAA RID: 3498
		private const int TargetRaidVillageCount = 3;

		// Token: 0x04000DAB RID: 3499
		private const IssueBase.IssueFrequency RaidAnEnemyTerritoryIssueFrequency = IssueBase.IssueFrequency.VeryCommon;

		// Token: 0x02000663 RID: 1635
		public class RaidAnEnemyTerritoryIssue : IssueBase
		{
			// Token: 0x0600525F RID: 21087 RVA: 0x0017628E File Offset: 0x0017448E
			internal static void AutoGeneratedStaticCollectObjectsRaidAnEnemyTerritoryIssue(object o, List<object> collectedObjects)
			{
				((RaidAnEnemyTerritoryIssueBehavior.RaidAnEnemyTerritoryIssue)o).AutoGeneratedInstanceCollectObjects(collectedObjects);
			}

			// Token: 0x06005260 RID: 21088 RVA: 0x0017629C File Offset: 0x0017449C
			protected override void AutoGeneratedInstanceCollectObjects(List<object> collectedObjects)
			{
				base.AutoGeneratedInstanceCollectObjects(collectedObjects);
				collectedObjects.Add(this._enemyKingdom);
			}

			// Token: 0x06005261 RID: 21089 RVA: 0x001762B1 File Offset: 0x001744B1
			internal static object AutoGeneratedGetMemberValue_enemyKingdom(object o)
			{
				return ((RaidAnEnemyTerritoryIssueBehavior.RaidAnEnemyTerritoryIssue)o)._enemyKingdom;
			}

			// Token: 0x1700116F RID: 4463
			// (get) Token: 0x06005262 RID: 21090 RVA: 0x001762C0 File Offset: 0x001744C0
			public override TextObject IssueBriefByIssueGiver
			{
				get
				{
					TextObject textObject = new TextObject("{=CrzFdo2H}Yes. It's about the war with the {ENEMYFACTION_INFORMALNAME}. [ib:hip][if:convo_excited]We need to tie up some of their forces. A relatively small force moving quickly through their lands and raiding their villages should be a good distraction. Their lords will need to chase the raiders and won't be able to threaten us elsewhere. You seem to be the right {?PLAYER.GENDER}warrior{?}man{\\?} for the job. What do you say? You'll have my gratitude and you'll be well rewarded if you succeed.", null);
					if (base.IssueOwner.GetTraitLevel(DefaultTraits.Mercy) + base.IssueOwner.GetTraitLevel(DefaultTraits.Honor) >= 0)
					{
						textObject = new TextObject("{=OlIWwLbP}Yes. It's about the war with the {ENEMYFACTION_INFORMALNAME}. [ib:closed][if:convo_pondering]We need to tie up some of their forces, and the easiest way to do that would be to raid their villages. It's a cruel business and will be hard on the common folk, but their lords will need to chase the raiders and it will prevent them from doing the same to us. If you take this on, I shall reward you if you succeed.", null);
					}
					textObject.SetTextVariable("ENEMYFACTION_INFORMALNAME", this._enemyKingdom.InformalName);
					StringHelpers.SetCharacterProperties("PLAYER", CharacterObject.PlayerCharacter, textObject, false);
					return textObject;
				}
			}

			// Token: 0x17001170 RID: 4464
			// (get) Token: 0x06005263 RID: 21091 RVA: 0x00176334 File Offset: 0x00174534
			public override TextObject IssueAcceptByPlayer
			{
				get
				{
					TextObject textObject = new TextObject("{=bLfXzCyc}I'm at your service my {?ISSUE_OWNER.GENDER}lady{?}lord{\\?}. Just tell me the details.", null);
					StringHelpers.SetCharacterProperties("ISSUE_OWNER", base.IssueOwner.CharacterObject, textObject, false);
					return textObject;
				}
			}

			// Token: 0x17001171 RID: 4465
			// (get) Token: 0x06005264 RID: 21092 RVA: 0x00176368 File Offset: 0x00174568
			public override TextObject IssueQuestSolutionExplanationByIssueGiver
			{
				get
				{
					TextObject textObject = new TextObject("{=aRfMtTUT}Good. See if you can hit {NUMBER_OF_TARGET_VILLAGE} villages. They won't be able to ignore that kind of damage. I'll give you {BASE_REWARD}{GOLD_ICON} for doing that, and {EXTRA_REWARD}{GOLD_ICON} more for every extra one that you raid. Agreed?[if:convo_mocking_revenge]", null);
					if (base.IssueOwner.GetTraitLevel(DefaultTraits.Mercy) + base.IssueOwner.GetTraitLevel(DefaultTraits.Honor) > 0)
					{
						textObject = new TextObject("{=AEVIa5sQ}So be it. See if you can hit {NUMBER_OF_TARGET_VILLAGE} villages. [if:convo_stern]They won't be able to ignore that, and it will put a dent in their revenues. I'll give you {BASE_REWARD}{GOLD_ICON} for doing that, and {EXTRA_REWARD}{GOLD_ICON} more for every extra one that you raid. Do you agree?", null);
					}
					textObject.SetTextVariable("NUMBER_OF_TARGET_VILLAGE", 3);
					textObject.SetTextVariable("BASE_REWARD", 15000);
					textObject.SetTextVariable("EXTRA_REWARD", 3000);
					return textObject;
				}
			}

			// Token: 0x17001172 RID: 4466
			// (get) Token: 0x06005265 RID: 21093 RVA: 0x001763E4 File Offset: 0x001745E4
			public override TextObject IssueQuestSolutionAcceptByPlayer
			{
				get
				{
					TextObject textObject = new TextObject("{=nrRvyKgL}I'll strike into their territory as you command, my {?ISSUE_OWNER.GENDER}lady{?}lord{\\?}.", null);
					StringHelpers.SetCharacterProperties("ISSUE_OWNER", base.IssueOwner.CharacterObject, textObject, false);
					return textObject;
				}
			}

			// Token: 0x17001173 RID: 4467
			// (get) Token: 0x06005266 RID: 21094 RVA: 0x00176416 File Offset: 0x00174616
			public override bool IsThereAlternativeSolution
			{
				get
				{
					return false;
				}
			}

			// Token: 0x17001174 RID: 4468
			// (get) Token: 0x06005267 RID: 21095 RVA: 0x00176419 File Offset: 0x00174619
			public override bool IsThereLordSolution
			{
				get
				{
					return false;
				}
			}

			// Token: 0x17001175 RID: 4469
			// (get) Token: 0x06005268 RID: 21096 RVA: 0x0017641C File Offset: 0x0017461C
			public override TextObject Title
			{
				get
				{
					return new TextObject("{=DSlhMswt}Raid an Enemy Territory", null);
				}
			}

			// Token: 0x17001176 RID: 4470
			// (get) Token: 0x06005269 RID: 21097 RVA: 0x0017642C File Offset: 0x0017462C
			public override TextObject Description
			{
				get
				{
					TextObject textObject = new TextObject("{=JEuZoV1E}{ISSUE_OWNER.LINK} asks you to raid enemy villages to distract enemy war parties.", null);
					StringHelpers.SetCharacterProperties("ISSUE_OWNER", base.IssueOwner.CharacterObject, textObject, false);
					return textObject;
				}
			}

			// Token: 0x0600526A RID: 21098 RVA: 0x0017645E File Offset: 0x0017465E
			public RaidAnEnemyTerritoryIssue(Hero issueGiver) : base(issueGiver, CampaignTime.DaysFromNow(60f))
			{
				this._enemyKingdom = (from k in Kingdom.All
				where k.IsAtWarWith(base.IssueOwner.MapFaction)
				select k).GetRandomElementInefficiently<Kingdom>();
			}

			// Token: 0x0600526B RID: 21099 RVA: 0x00176492 File Offset: 0x00174692
			protected override float GetIssueEffectAmountInternal(IssueEffect issueEffect)
			{
				if (issueEffect == DefaultIssueEffects.ClanInfluence)
				{
					return -0.1f;
				}
				return 0f;
			}

			// Token: 0x0600526C RID: 21100 RVA: 0x001764A7 File Offset: 0x001746A7
			protected override void OnGameLoad()
			{
			}

			// Token: 0x0600526D RID: 21101 RVA: 0x001764A9 File Offset: 0x001746A9
			protected override void HourlyTick()
			{
			}

			// Token: 0x0600526E RID: 21102 RVA: 0x001764AB File Offset: 0x001746AB
			protected override QuestBase GenerateIssueQuest(string questId)
			{
				return new RaidAnEnemyTerritoryIssueBehavior.RaidAnEnemyTerritoryQuest(questId, base.IssueOwner, CampaignTime.DaysFromNow(60f), this._enemyKingdom);
			}

			// Token: 0x0600526F RID: 21103 RVA: 0x001764C9 File Offset: 0x001746C9
			public override IssueBase.IssueFrequency GetFrequency()
			{
				return IssueBase.IssueFrequency.VeryCommon;
			}

			// Token: 0x06005270 RID: 21104 RVA: 0x001764CC File Offset: 0x001746CC
			protected override bool CanPlayerTakeQuestConditions(Hero issueGiver, out IssueBase.PreconditionFlags flag, out Hero relationHero, out SkillObject skill)
			{
				flag = IssueBase.PreconditionFlags.None;
				relationHero = null;
				skill = null;
				if (issueGiver.GetRelationWithPlayer() < -10f)
				{
					relationHero = issueGiver;
					flag |= IssueBase.PreconditionFlags.Relation;
				}
				if (Clan.PlayerClan.Kingdom != issueGiver.MapFaction)
				{
					flag |= IssueBase.PreconditionFlags.NotInSameFaction;
				}
				return flag == IssueBase.PreconditionFlags.None;
			}

			// Token: 0x06005271 RID: 21105 RVA: 0x0017651A File Offset: 0x0017471A
			public override bool IssueStayAliveConditions()
			{
				return this._enemyKingdom.IsAtWarWith(base.IssueOwner.MapFaction) && !this._enemyKingdom.IsEliminated && base.IssueOwner.MapFaction.IsKingdomFaction;
			}

			// Token: 0x06005272 RID: 21106 RVA: 0x00176553 File Offset: 0x00174753
			protected override void CompleteIssueWithTimedOutConsequences()
			{
			}

			// Token: 0x04001AD8 RID: 6872
			private const int IssueDurationInDays = 60;

			// Token: 0x04001AD9 RID: 6873
			private const int RelationLimitWithPlayer = -10;

			// Token: 0x04001ADA RID: 6874
			[SaveableField(10)]
			private readonly Kingdom _enemyKingdom;
		}

		// Token: 0x02000664 RID: 1636
		public class RaidAnEnemyTerritoryQuest : QuestBase
		{
			// Token: 0x06005274 RID: 21108 RVA: 0x00176568 File Offset: 0x00174768
			internal static void AutoGeneratedStaticCollectObjectsRaidAnEnemyTerritoryQuest(object o, List<object> collectedObjects)
			{
				((RaidAnEnemyTerritoryIssueBehavior.RaidAnEnemyTerritoryQuest)o).AutoGeneratedInstanceCollectObjects(collectedObjects);
			}

			// Token: 0x06005275 RID: 21109 RVA: 0x00176576 File Offset: 0x00174776
			protected override void AutoGeneratedInstanceCollectObjects(List<object> collectedObjects)
			{
				base.AutoGeneratedInstanceCollectObjects(collectedObjects);
				collectedObjects.Add(this._raidedVillagesTrackLog);
				collectedObjects.Add(this._enemyKingdom);
				collectedObjects.Add(this._raidedVillages);
			}

			// Token: 0x06005276 RID: 21110 RVA: 0x001765A3 File Offset: 0x001747A3
			internal static object AutoGeneratedGetMemberValue_raidedVillagesTrackLog(object o)
			{
				return ((RaidAnEnemyTerritoryIssueBehavior.RaidAnEnemyTerritoryQuest)o)._raidedVillagesTrackLog;
			}

			// Token: 0x06005277 RID: 21111 RVA: 0x001765B0 File Offset: 0x001747B0
			internal static object AutoGeneratedGetMemberValue_enemyKingdom(object o)
			{
				return ((RaidAnEnemyTerritoryIssueBehavior.RaidAnEnemyTerritoryQuest)o)._enemyKingdom;
			}

			// Token: 0x06005278 RID: 21112 RVA: 0x001765BD File Offset: 0x001747BD
			internal static object AutoGeneratedGetMemberValue_raidedVillages(object o)
			{
				return ((RaidAnEnemyTerritoryIssueBehavior.RaidAnEnemyTerritoryQuest)o)._raidedVillages;
			}

			// Token: 0x17001177 RID: 4471
			// (get) Token: 0x06005279 RID: 21113 RVA: 0x001765CA File Offset: 0x001747CA
			public override TextObject Title
			{
				get
				{
					return new TextObject("{=DSlhMswt}Raid an Enemy Territory", null);
				}
			}

			// Token: 0x17001178 RID: 4472
			// (get) Token: 0x0600527A RID: 21114 RVA: 0x001765D7 File Offset: 0x001747D7
			public override bool IsRemainingTimeHidden
			{
				get
				{
					return false;
				}
			}

			// Token: 0x17001179 RID: 4473
			// (get) Token: 0x0600527B RID: 21115 RVA: 0x001765DC File Offset: 0x001747DC
			private TextObject _questAcceptedByPlayerLog
			{
				get
				{
					TextObject textObject = new TextObject("{=sYfvsMwN}{QUEST_GIVER.LINK} asked you to raid {NUMBER_OF_TARGET_VILLAGE} {ENEMYFACTION_INFORMALNAME} villages to distract their lords and weaken their armies. {?QUEST_GIVER.GENDER}She{?}He{\\?} offers {REWARD_GOLD}{GOLD_ICON} to thank you for your deeds.", null);
					StringHelpers.SetCharacterProperties("QUEST_GIVER", base.QuestGiver.CharacterObject, textObject, false);
					textObject.SetTextVariable("NUMBER_OF_TARGET_VILLAGE", 3);
					textObject.SetTextVariable("ENEMYFACTION_INFORMALNAME", this._enemyKingdom.InformalName);
					textObject.SetTextVariable("EXTRA_REWARD", 3000);
					textObject.SetTextVariable("GOLD_ICON", "{=!}<img src=\"General\\Icons\\Coin@2x\" extend=\"8\">");
					textObject.SetTextVariable("REWARD_GOLD", 15000);
					return textObject;
				}
			}

			// Token: 0x1700117A RID: 4474
			// (get) Token: 0x0600527C RID: 21116 RVA: 0x00176665 File Offset: 0x00174865
			private TextObject _mainHeroRaidedAllVillagesLog
			{
				get
				{
					return new TextObject("{=gMvDCnlx}You have successfully raided enemy villages and distracted enemy forces as promised.", null);
				}
			}

			// Token: 0x1700117B RID: 4475
			// (get) Token: 0x0600527D RID: 21117 RVA: 0x00176674 File Offset: 0x00174874
			private TextObject _mainHeroCouldNotRaidedAllVillagesLog
			{
				get
				{
					TextObject textObject = new TextObject("{=nRkLFBMl}You failed to raid at least {NUMBER_OF_TARGET_VILLAGE} villages and then report back. {QUEST_GIVER.LINK} is disappointed.", null);
					StringHelpers.SetCharacterProperties("QUEST_GIVER", base.QuestGiver.CharacterObject, textObject, false);
					return textObject;
				}
			}

			// Token: 0x1700117C RID: 4476
			// (get) Token: 0x0600527E RID: 21118 RVA: 0x001766A8 File Offset: 0x001748A8
			private TextObject _questGiverDiedLog
			{
				get
				{
					TextObject textObject = new TextObject("{=65BTaOl8}{QUEST_GIVER.LINK} died and your mission is canceled.", null);
					StringHelpers.SetCharacterProperties("QUEST_GIVER", base.QuestGiver.CharacterObject, textObject, false);
					return textObject;
				}
			}

			// Token: 0x1700117D RID: 4477
			// (get) Token: 0x0600527F RID: 21119 RVA: 0x001766DC File Offset: 0x001748DC
			private TextObject _enemyIsOutOfVillagesLog
			{
				get
				{
					TextObject textObject = new TextObject("{=bIDvq6wA}The enemy no longer holds any villages. {QUEST_GIVER.LINK} has canceled your mission.", null);
					StringHelpers.SetCharacterProperties("QUEST_GIVER", base.QuestGiver.CharacterObject, textObject, false);
					return textObject;
				}
			}

			// Token: 0x1700117E RID: 4478
			// (get) Token: 0x06005280 RID: 21120 RVA: 0x00176710 File Offset: 0x00174910
			private TextObject _declaredWarOnQuestGiverFactionLog
			{
				get
				{
					TextObject textObject = new TextObject("{=2diuD0rT}Your clan/faction is now at war with {QUEST_GIVER.LINK}'s faction. Your agreement with {QUEST_GIVER.LINK} has been canceled.", null);
					StringHelpers.SetCharacterProperties("QUEST_GIVER", base.QuestGiver.CharacterObject, textObject, false);
					return textObject;
				}
			}

			// Token: 0x1700117F RID: 4479
			// (get) Token: 0x06005281 RID: 21121 RVA: 0x00176744 File Offset: 0x00174944
			private TextObject _playerDeclaredWarQuestLogText
			{
				get
				{
					TextObject textObject = new TextObject("{=bqeWVVEE}Your actions have started a war with {QUEST_GIVER.LINK}'s faction. {?QUEST_GIVER.GENDER}She{?}He{\\?} cancels your agreement and the quest is a failure.", null);
					StringHelpers.SetCharacterProperties("QUEST_GIVER", base.QuestGiver.CharacterObject, textObject, false);
					return textObject;
				}
			}

			// Token: 0x17001180 RID: 4480
			// (get) Token: 0x06005282 RID: 21122 RVA: 0x00176778 File Offset: 0x00174978
			private TextObject _declaredPeaceBetweenQuestGiverAndEnemyFactionsLog
			{
				get
				{
					TextObject textObject = new TextObject("{=AXsbnTBb}{QUEST_GIVER.LINK} has made peace with the {ENEMYFACTION_INFORMALNAME}. Your agreement with {QUEST_GIVER.LINK} has been canceled.", null);
					StringHelpers.SetCharacterProperties("QUEST_GIVER", base.QuestGiver.CharacterObject, textObject, false);
					textObject.SetTextVariable("ENEMYFACTION_INFORMALNAME", this._enemyKingdom.InformalName);
					return textObject;
				}
			}

			// Token: 0x17001181 RID: 4481
			// (get) Token: 0x06005283 RID: 21123 RVA: 0x001767C1 File Offset: 0x001749C1
			private TextObject _factionLeftLog
			{
				get
				{
					TextObject textObject = new TextObject("{=c63DWZhr}You left {FACTION}. Your agreement with {QUEST_GIVER.LINK} is terminated.", null);
					textObject.SetTextVariable("FACTION", base.QuestGiver.MapFaction.EncyclopediaLinkWithName);
					textObject.SetCharacterProperties("QUEST_GIVER", base.QuestGiver.CharacterObject, false);
					return textObject;
				}
			}

			// Token: 0x06005284 RID: 21124 RVA: 0x00176801 File Offset: 0x00174A01
			public RaidAnEnemyTerritoryQuest(string questId, Hero questGiver, CampaignTime duration, Kingdom enemyKingdom) : base(questId, questGiver, duration, 15000)
			{
				this._enemyKingdom = enemyKingdom;
				this._raidedVillages = new List<Settlement>();
				this.SetDialogs();
				base.InitializeQuestOnCreation();
			}

			// Token: 0x06005285 RID: 21125 RVA: 0x00176830 File Offset: 0x00174A30
			protected override void InitializeQuestOnGameLoad()
			{
				this.SetDialogs();
			}

			// Token: 0x06005286 RID: 21126 RVA: 0x00176838 File Offset: 0x00174A38
			protected override void HourlyTick()
			{
			}

			// Token: 0x06005287 RID: 21127 RVA: 0x0017683A File Offset: 0x00174A3A
			protected override void OnTimedOut()
			{
				if (this._raidedVillages.Count >= 3)
				{
					this.MainHeroRaidedAllVillages();
					return;
				}
				this.MainHeroCouldNotRaidedAllVillages();
			}

			// Token: 0x06005288 RID: 21128 RVA: 0x00176857 File Offset: 0x00174A57
			protected override void OnBeforeTimedOut(ref bool completeWithSuccess, ref bool doNotResolveTheQuest)
			{
				if (this._raidedVillages.Count >= 3)
				{
					completeWithSuccess = true;
				}
			}

			// Token: 0x06005289 RID: 21129 RVA: 0x0017686C File Offset: 0x00174A6C
			protected override void RegisterEvents()
			{
				base.RegisterEvents();
				CampaignEvents.DailyTickEvent.AddNonSerializedListener(this, new Action(this.DailyTick));
				CampaignEvents.RaidCompletedEvent.AddNonSerializedListener(this, new Action<BattleSideEnum, RaidEventComponent>(this.OnRaidCompleted));
				CampaignEvents.HeroKilledEvent.AddNonSerializedListener(this, new Action<Hero, Hero, KillCharacterAction.KillCharacterActionDetail, bool>(this.OnHeroKilled));
				CampaignEvents.OnSettlementOwnerChangedEvent.AddNonSerializedListener(this, new Action<Settlement, bool, Hero, Hero, Hero, ChangeOwnerOfSettlementAction.ChangeOwnerOfSettlementDetail>(this.OnSettlementOwnerChanged));
				CampaignEvents.WarDeclared.AddNonSerializedListener(this, new Action<IFaction, IFaction, DeclareWarAction.DeclareWarDetail>(this.OnWarDeclared));
				CampaignEvents.MakePeace.AddNonSerializedListener(this, new Action<IFaction, IFaction, MakePeaceAction.MakePeaceDetail>(this.OnMakePeace));
				CampaignEvents.OnClanChangedKingdomEvent.AddNonSerializedListener(this, new Action<Clan, Kingdom, Kingdom, ChangeKingdomAction.ChangeKingdomActionDetail, bool>(this.OnClanChangedKingdom));
			}

			// Token: 0x0600528A RID: 21130 RVA: 0x00176920 File Offset: 0x00174B20
			private void OnClanChangedKingdom(Clan clan, Kingdom oldKingdom, Kingdom newKingdom, ChangeKingdomAction.ChangeKingdomActionDetail detail, bool showNotification = true)
			{
				if (clan == Clan.PlayerClan && oldKingdom == base.QuestGiver.MapFaction)
				{
					this.FactionLeft();
				}
			}

			// Token: 0x0600528B RID: 21131 RVA: 0x00176940 File Offset: 0x00174B40
			private void DailyTick()
			{
				if (base.QuestDueTime.IsPast && this._raidedVillages.Count >= 3)
				{
					this.MainHeroRaidedAllVillages();
				}
			}

			// Token: 0x0600528C RID: 21132 RVA: 0x00176974 File Offset: 0x00174B74
			private void OnRaidCompleted(BattleSideEnum winnerSide, RaidEventComponent raidEvent)
			{
				MapEvent mapEvent = raidEvent.MapEvent;
				if (mapEvent.IsRaid && mapEvent.IsPlayerMapEvent && mapEvent.MapEventSettlement.IsVillage && mapEvent.PlayerSide == winnerSide && !this._raidedVillages.Contains(mapEvent.MapEventSettlement))
				{
					this._raidedVillages.Add(mapEvent.MapEventSettlement);
					this._raidedVillagesTrackLog.UpdateCurrentProgress(this._raidedVillages.Count);
					if (this._raidedVillages.Count >= 3)
					{
						TextObject textObject = new TextObject("{=VM9xDun7}You have successfully raided target villages. Go back to {QUEST_GIVER.LINK} to get your reward.", null);
						textObject.SetCharacterProperties("QUEST_GIVER", base.QuestGiver.CharacterObject, false);
						MBInformationManager.AddQuickInformation(textObject, 0, null, "");
					}
				}
			}

			// Token: 0x0600528D RID: 21133 RVA: 0x00176A2A File Offset: 0x00174C2A
			private void OnHeroKilled(Hero victim, Hero killer, KillCharacterAction.KillCharacterActionDetail detail, bool showNotification = true)
			{
				if (victim == base.QuestGiver)
				{
					if (this._raidedVillages.Count < 3)
					{
						this.QuestGiverDied();
						return;
					}
					this.MainHeroRaidedAllVillages();
				}
			}

			// Token: 0x0600528E RID: 21134 RVA: 0x00176A50 File Offset: 0x00174C50
			private void OnSettlementOwnerChanged(Settlement settlement, bool openToClaim, Hero newOwner, Hero oldOwner, Hero capturerHero, ChangeOwnerOfSettlementAction.ChangeOwnerOfSettlementDetail detail)
			{
				if (oldOwner.MapFaction == this._enemyKingdom && this._enemyKingdom.Settlements.Count < 3 - this._raidedVillages.Count)
				{
					if (this._raidedVillages.Count < 3)
					{
						this.EnemyIsOutOfVillages();
						return;
					}
					this.MainHeroRaidedAllVillages();
				}
			}

			// Token: 0x0600528F RID: 21135 RVA: 0x00176AA8 File Offset: 0x00174CA8
			private void OnWarDeclared(IFaction faction1, IFaction faction2, DeclareWarAction.DeclareWarDetail detail)
			{
				if ((faction1 == base.QuestGiver.MapFaction && faction2 == Clan.PlayerClan) || (faction1 == Clan.PlayerClan && faction2 == base.QuestGiver.MapFaction))
				{
					if (this._raidedVillages.Count < 3)
					{
						QuestHelper.CheckWarDeclarationAndFailOrCancelTheQuest(this, faction1, faction2, detail, this._playerDeclaredWarQuestLogText, this._declaredWarOnQuestGiverFactionLog, false);
						return;
					}
					this.MainHeroRaidedAllVillages();
				}
			}

			// Token: 0x06005290 RID: 21136 RVA: 0x00176B0C File Offset: 0x00174D0C
			private void OnMakePeace(IFaction side1Faction, IFaction side2Faction, MakePeaceAction.MakePeaceDetail detail)
			{
				if ((side1Faction == base.QuestGiver.MapFaction && side2Faction == this._enemyKingdom) || (side1Faction == this._enemyKingdom && side2Faction == base.QuestGiver.MapFaction))
				{
					if (this._raidedVillages.Count < 3)
					{
						this.DeclaredPeaceBetweenQuestGiverAndEnemyFactions();
						return;
					}
					this.MainHeroRaidedAllVillages();
				}
			}

			// Token: 0x06005291 RID: 21137 RVA: 0x00176B64 File Offset: 0x00174D64
			protected override void SetDialogs()
			{
				this.OfferDialogFlow = DialogFlow.CreateDialogFlow("issue_classic_quest_start", 100).NpcLine(new TextObject("{=R21SLyGK}Excellent. You are a brave and loyal warrior. You have my thanks.[ib:hip][if:convo_excited]", null), null, null).Condition(() => Hero.OneToOneConversationHero == base.QuestGiver).Consequence(new ConversationSentence.OnConsequenceDelegate(this.QuestAcceptedByPlayerConsequences)).CloseDialog();
				this.DiscussDialogFlow = DialogFlow.CreateDialogFlow("quest_discuss", 100).NpcLine(new TextObject("{=eMrClHp2}Is there any progress on the task I gave you?[ib:hip][if:convo_astonished]", null), null, null).Condition(new ConversationSentence.OnConditionDelegate(this.DiscussCondition)).BeginPlayerOptions().PlayerOption(new TextObject("{=XOv5B84a}Yes, my {?QUEST_GIVER.GENDER}lady{?}lord{\\?}. I raided {RAIDED_VILLAGE_COUNT} villages as you commanded.", null), null).Condition(() => this._raidedVillages.Count >= 3).NpcLine(new TextObject("{=J4yakjtP}Splendid. You have served me well. Take your well-earned reward.[ib:hip][if:convo_grateful]", null), null, null).Consequence(delegate
				{
					this.MainHeroRaidedAllVillages();
					MapEventHelper.OnConversationEnd();
				}).CloseDialog().PlayerOption(new TextObject("{=8JvcDnh6}Not yet my {?QUEST_GIVER.GENDER}lady{?}lord{\\?}. I am working on it.", null), null).NpcLine(new TextObject("{=EuhvSsPZ}Good. Keep them busy.[if:convo_normal]", null), null, null).Consequence(new ConversationSentence.OnConsequenceDelegate(MapEventHelper.OnConversationEnd)).CloseDialog().PlayerOption(new TextObject("{=pnQN6LrV}The time is not quite right, my {?QUEST_GIVER.GENDER}lady{?}lord{\\?}. I don't want to ride into a trap.", null), null).NpcLine(new TextObject("{=DXD3ag49}Well... I hope this delay is for a good reason.[ib:closed2][if:convo_thinking]", null), null, null).Consequence(new ConversationSentence.OnConsequenceDelegate(MapEventHelper.OnConversationEnd)).CloseDialog().EndPlayerOptions().CloseDialog();
			}

			// Token: 0x06005292 RID: 21138 RVA: 0x00176CBC File Offset: 0x00174EBC
			private void QuestAcceptedByPlayerConsequences()
			{
				base.StartQuest();
				this._raidedVillagesTrackLog = base.AddDiscreteLog(this._questAcceptedByPlayerLog, new TextObject("{=RFH1lDMj}Raided Village Count", null), 0, 3, null, false);
			}

			// Token: 0x06005293 RID: 21139 RVA: 0x00176CE5 File Offset: 0x00174EE5
			private bool DiscussCondition()
			{
				if (Hero.OneToOneConversationHero == base.QuestGiver)
				{
					StringHelpers.SetCharacterProperties("QUEST_GIVER", base.QuestGiver.CharacterObject, null, false);
					MBTextManager.SetTextVariable("RAIDED_VILLAGE_COUNT", this._raidedVillages.Count);
					return true;
				}
				return false;
			}

			// Token: 0x06005294 RID: 21140 RVA: 0x00176D24 File Offset: 0x00174F24
			private void MainHeroRaidedAllVillages()
			{
				base.AddLog(this._mainHeroRaidedAllVillagesLog, false);
				Clan.PlayerClan.AddRenown(5f, true);
				TraitLevelingHelper.OnIssueSolvedThroughQuest(Hero.MainHero, new Tuple<TraitObject, int>[]
				{
					new Tuple<TraitObject, int>(DefaultTraits.Honor, 10)
				});
				ChangeClanInfluenceAction.Apply(Clan.PlayerClan, 20f);
				this.RelationshipChangeWithQuestGiver = 10;
				GiveGoldAction.ApplyBetweenCharacters(null, Hero.MainHero, this.RewardGold, false);
				if (this._raidedVillages.Count > 3)
				{
					int amount = (this._raidedVillages.Count - 3) * 3000;
					GiveGoldAction.ApplyBetweenCharacters(null, Hero.MainHero, amount, false);
				}
				base.CompleteQuestWithSuccess();
			}

			// Token: 0x06005295 RID: 21141 RVA: 0x00176DCC File Offset: 0x00174FCC
			private void MainHeroCouldNotRaidedAllVillages()
			{
				base.AddLog(this._mainHeroCouldNotRaidedAllVillagesLog, false);
				TraitLevelingHelper.OnIssueSolvedThroughQuest(Hero.MainHero, new Tuple<TraitObject, int>[]
				{
					new Tuple<TraitObject, int>(DefaultTraits.Honor, -10)
				});
				this.RelationshipChangeWithQuestGiver = -5;
			}

			// Token: 0x06005296 RID: 21142 RVA: 0x00176E03 File Offset: 0x00175003
			private void QuestGiverDied()
			{
				base.AddLog(this._questGiverDiedLog, false);
				base.CompleteQuestWithCancel(null);
			}

			// Token: 0x06005297 RID: 21143 RVA: 0x00176E1A File Offset: 0x0017501A
			private void EnemyIsOutOfVillages()
			{
				base.AddLog(this._enemyIsOutOfVillagesLog, false);
				base.CompleteQuestWithCancel(null);
			}

			// Token: 0x06005298 RID: 21144 RVA: 0x00176E31 File Offset: 0x00175031
			private void DeclaredPeaceBetweenQuestGiverAndEnemyFactions()
			{
				base.AddLog(this._declaredPeaceBetweenQuestGiverAndEnemyFactionsLog, false);
				base.CompleteQuestWithCancel(null);
			}

			// Token: 0x06005299 RID: 21145 RVA: 0x00176E48 File Offset: 0x00175048
			private void FactionLeft()
			{
				base.AddLog(this._factionLeftLog, false);
				base.CompleteQuestWithCancel(null);
			}

			// Token: 0x04001ADB RID: 6875
			private const int RenownBonus = 5;

			// Token: 0x04001ADC RID: 6876
			private const int HonorXpBonus = 10;

			// Token: 0x04001ADD RID: 6877
			private const int InfluenceBonus = 20;

			// Token: 0x04001ADE RID: 6878
			private const int RelationBonusWithQuestGiver = 10;

			// Token: 0x04001ADF RID: 6879
			private const int HonorXpPenalty = -10;

			// Token: 0x04001AE0 RID: 6880
			private const int RelationPenaltyWithQuestGiver = -5;

			// Token: 0x04001AE1 RID: 6881
			[SaveableField(10)]
			private JournalLog _raidedVillagesTrackLog;

			// Token: 0x04001AE2 RID: 6882
			[SaveableField(20)]
			private readonly Kingdom _enemyKingdom;

			// Token: 0x04001AE3 RID: 6883
			[SaveableField(30)]
			private readonly List<Settlement> _raidedVillages;
		}

		// Token: 0x02000665 RID: 1637
		public class RaidAnEnemyTerritoryIssueTypeDefiner : SaveableTypeDefiner
		{
			// Token: 0x0600529D RID: 21149 RVA: 0x00176E8E File Offset: 0x0017508E
			public RaidAnEnemyTerritoryIssueTypeDefiner() : base(586800)
			{
			}

			// Token: 0x0600529E RID: 21150 RVA: 0x00176E9B File Offset: 0x0017509B
			protected override void DefineClassTypes()
			{
				base.AddClassDefinition(typeof(RaidAnEnemyTerritoryIssueBehavior.RaidAnEnemyTerritoryIssue), 1, null);
				base.AddClassDefinition(typeof(RaidAnEnemyTerritoryIssueBehavior.RaidAnEnemyTerritoryQuest), 2, null);
			}
		}
	}
}
